<?php
	namespace Model;
	use Think\Model;
	class DbModel extends Model{
		protected $tableName = 'user';
		/*
		 * 拼接update语句的函数
		 * $table:要修改的表名
		 * $datas：要修改的数据，可以是数组，也可以是字符串
		 * $where:sql语句的where部分,
		 * */
		function updatedata($table,$datas,$where){
//			echo $table;
		$sql="update ".$table." set ";
		if(is_array($datas)){
			foreach($datas as $k=>$v){
				$sql.=$k."='".$v."',";
			}
			$sql = substr($sql,0,strlen($sql)-1);
			
		}else{
			$sql.=$datas;
		}
			$sql.=" where ".$where.";";
//			$this->execute($sql);
			return $this->execute($sql);	
		}
		//修改字段为表达式时用的函数，例如 set id=id+1
		function updatedataforint($table,$datas,$where){
//			echo $table;
		$sql="update ".$table." set ";
		if(is_array($datas)){
			foreach($datas as $k=>$v){
				$sql.=$k."=".$v.",";
			}
			$sql = substr($sql,0,strlen($sql)-1);
			
		}else{
			$sql.=$datas;
		}
			$sql.=" where ".$where.";";
//			$this->execute($sql);
			return $this->execute($sql);	
		}
	}
?>